﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SLG.Domain.Strategy
{
    /// <summary>
    /// 为第一次创建王国的时候，在主城创建默认的建筑物
    /// </summary>
    class DefaultBuildingStrategy
    {   
        public static void Build(SLGDbContext dbContext, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            EntRep<Entities.T_Building> bRep = new EntRep<Entities.T_Building>(dbContext);

            // 创建一个大厅
            BuildCityHall(bRep, serverId, userId, kingdomId, cityId, ref now);

            BuildBattleHall(bRep, serverId, userId, kingdomId, cityId, ref now);

            // 创建一个酒馆
            BuildTavern(bRep, serverId, userId, kingdomId, cityId, ref now);
        }

        private static void BuildCityHall(EntRep<Entities.T_Building> rep, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            // 创建一个大厅
            Entities.T_Building cityHall = new Entities.T_Building();
            cityHall.Id = Guid.NewGuid();
            cityHall.CityId = cityId;
            cityHall.CreatedTime = now;
            cityHall.Experience = 0;
            cityHall.KingdomId = kingdomId;
            cityHall.Name = "City Hall";
            cityHall.Position = 0;
            cityHall.Level = 1;
            cityHall.ServerId = serverId;
            cityHall.UserId = userId;
            cityHall.Type = DEF.BuildingTypes.CityHall;

            rep.Create(cityHall);
        }

        private static void BuildBattleHall(EntRep<Entities.T_Building> rep, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            // 创建一个大厅
            Entities.T_Building battleHall = new Entities.T_Building();
            battleHall.Id = Guid.NewGuid();
            battleHall.CityId = cityId;
            battleHall.CreatedTime = now;
            battleHall.Experience = 0;
            battleHall.KingdomId = kingdomId;
            battleHall.Name = "Battle Hall";
            battleHall.Position = 1;
            battleHall.Level = 1;
            battleHall.ServerId = serverId;
            battleHall.UserId = userId;
            battleHall.Type = DEF.BuildingTypes.BattleHall;

            rep.Create(battleHall);
        }

        private static void BuildTavern(EntRep<Entities.T_Building> rep, int serverId, int userId, Guid kingdomId, Guid cityId, ref DateTime now)
        {
            // 创建一个大厅
            Entities.T_Building hall = new Entities.T_Building();
            hall.Id = Guid.NewGuid();
            hall.CityId = cityId;
            hall.CreatedTime = now;
            hall.Experience = 0;
            hall.KingdomId = kingdomId;
            hall.Name = "Tavern";
            hall.Position = 2;
            hall.Level = 1;
            hall.ServerId = serverId;
            hall.UserId = userId;
            hall.Type = DEF.BuildingTypes.Tavern;

            rep.Create(hall);
        }
    }
}
